package com.example.shixunandjavagotoyangchen.BoosYang;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.example.modelviewpresenter.View.BasterActivity;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.BlankFragmentDay001;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.BlankFragmentDay002;
import com.example.shixunandjavagotoyangchen.BoosYang.Day003.BlankFragmentDay003;
import com.example.shixunandjavagotoyangchen.BoosYang.Day004.BlankFragmentDay004;
import com.example.shixunandjavagotoyangchen.BoosYang.Day005.BlankFragmentDay005;
import com.example.shixunandjavagotoyangchen.Sunshine.FragmentSpaek.FragmentSpaek1;
import com.example.shixunandjavagotoyangchen.R;

import java.util.ArrayList;
import java.util.List;
@Route(path = "/login/main")
public class BoosYangActivity extends BasterActivity {

    private   androidx.viewpager.widget.ViewPager BoosViewPager;
    private android.widget.RadioGroup BoosRadioGroup;
    private android.widget.RadioButton BoosRadioButton1;
    private android.widget.RadioButton BoosRadioButton2;
    private android.widget.RadioButton BoosRadioButton3;
    private android.widget.RadioButton BoosRadioButton4;
    private android.widget.RadioButton BoosRadioButton5;



    @Override
    public int BandLayout() {
        return R.layout.activity_boos_yang;
    }

    @Override
    public void initView() {
        onWindowFocusChanged(true);
        BoosViewPager = (ViewPager) findViewById(R.id.Boos_ViewPager);
        BoosRadioGroup = (RadioGroup) findViewById(R.id.Boos_RadioGroup);
        BoosRadioButton1 = (RadioButton) findViewById(R.id.Boos_RadioButton1);
        BoosRadioButton2 = (RadioButton) findViewById(R.id.Boos_RadioButton2);
        BoosRadioButton3 = (RadioButton) findViewById(R.id.Boos_RadioButton3);
        BoosRadioButton4 = (RadioButton) findViewById(R.id.Boos_RadioButton4);
        BoosRadioButton5 = (RadioButton) findViewById(R.id.Boos_RadioButton5);
    }

    @Override
    public void initDate() {

        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new BlankFragmentDay001());
        fragments.add(new BlankFragmentDay002());
        fragments.add(new BlankFragmentDay003());
        fragments.add(new BlankFragmentDay004());
        fragments.add(new BlankFragmentDay005());


        FragmentSpaek1 fragmentSpaek1 = new FragmentSpaek1(getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT,fragments);
        BoosViewPager.setAdapter(fragmentSpaek1);

        BoosRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                switch (i)
                {
                    case R.id.Boos_RadioButton1:
                        BoosViewPager.setCurrentItem(0);
                        break;

                    case R.id.Boos_RadioButton2:
                        BoosViewPager.setCurrentItem(1);
                        break;

                    case R.id.Boos_RadioButton3:
                        BoosViewPager.setCurrentItem(2);
                        break;


                    case R.id.Boos_RadioButton4:
                        BoosViewPager.setCurrentItem(3);
                        break;


                    case R.id.Boos_RadioButton5:
                        BoosViewPager.setCurrentItem(4);
                        break;
                }
            }
        });
        BoosViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position){
                    case 0:
                        BoosRadioGroup.check(R.id.Boos_RadioButton1);
                        break;
                    case 1:
                        BoosRadioGroup.check(R.id.Boos_RadioButton2);
                        break;
                    case 2:
                        BoosRadioGroup.check(R.id.Boos_RadioButton3);
                        break;
                    case 3:
                        BoosRadioGroup.check(R.id.Boos_RadioButton4);
                        break;
                    case 4:
                        BoosRadioGroup.check(R.id.Boos_RadioButton5);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }



    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}
